Fork me on GitHub

Python Study Note (Last update: 2014-2-21)

Python Study Note

2014-02-17

About Unicode (python 3.3) When using \xxx to display Unicode characters, the encoding of the source file also counts. e.g, if you type:

    s = '\xc4'
    print(s)

In a GBK based file, interpreter says:

    Error:
    UnicodeEncodeError: 'gbk' codec can't encode character '\xc4' in 
    position 2: illegal multibyte sequence

On the other hand, inside a UTF-8 file:

    'Ä'

About Statements Refer to: Page 320, Learning Python 5th, O'Reilly, ISBN: 978-1-449-35573-9

Statements

Statements_2

About ++/--

In python, there is no ++/-- operator, see Stack Overflow and Python IAQ for more.

However ++x makes sense, which means +(+(x)), so basically it's simply x.

About Assignment Statements

Refer to: Page 340, Learning Python 5th, O'Reilly, ISBN: 978-1-449-35573-9

Assignment Statements

Argumented Assignment, Performance

If the subject is mutable and supports this operation, an augmented assignment may run even quicker by choosing an in-place update operation instead of an object copy.

About Divide and Mod

See the difference of 3/10 and 3//10. / means divide and result in decimal number, // means "mod" and results in integer. (A new feature in python 3)

2014-02-26

The strange loop:else:

Try this code:

x = 1
while x < 3:
    x = int( input('Int(try > 3 and = 1):') )
    if x == 1:
        break
else:
    print('Wow!')

And see this two article:For/else,python的while loop中的else多余吗?

The else will only be executed when for loop finishes normally or while loop is entered but not breaked.

Python really wants to keep code simple.

blogroll

social